#delimit;
set more off;

cd "C:\....\Replication files";
	
use "ENMI - replication.dta", clear;
	
 #delimit;
 set more off;
 
/* Mixed Effects replications */

xtmixed pvote c.ensh_mi##inc_cab_l  pvote_l
 	|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_enmi_simple;	
			 

xtmixed pvote
	c.ensh_mi##i.inc_cab_l pvote_l
	c.GDPgrowth##i.inc_cab_l
	c.moderate##i.inc_cab_l

	1.nparty
 majelect federal directpres ,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_enmi_full;	
		 
 xtmixed pvote
	c.ensh_mi pvote_l
	c.GDPgrowth
	c.moderate

	1.nparty
 majelect federal directpres if inc_cab_l==0,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_enmi_opponly;	
	
	
	xtmixed pvote
	c.ensh_mi#i.inc_cab_l pvote_l
	c.GDPgrowth#i.inc_cab_l
	c.moderate#i.inc_cab_l

	1.nparty
 majelect federal directpres if inc_cab_l==1,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_enmi_incumbentonly;	
		 
		 
		  
	 #delimit;
 esttab  ME_enmi_opponly ME_enmi_incumbentonly ME_enmi_full 
 using "figures\TableA6 - Mixed Effects.rtf", replace 
		b (%10.3f) se scalars("aic AIC" "bic BIC" "rmse Root Mean Squared Error" "ll Log-Likelihood" ) 
		obslast star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
		label mtitles ( "Opposition" "Incumbents" "Full") nogaps
		title (\label{})
order(ensh_mi 
1.inc_cab_l#c.ensh_mi
moderate 
1.inc_cab_l#c.moderate
GDPgrowth
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l 
1.nparty
	
 majelect federal directpres
 pvote_l _cons ) 

keep(ensh_mi 1.inc_cab_l 
1.inc_cab_l#c.ensh_mi GDPgrowth 
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l#c.moderate
moderate 1.nparty majelect 	
 federal directpres
pvote_l _cons )  

 coeflabels(
ensh_mi "ENMI" 
1.inc_cab_l "Incumbent"
1.inc_cab_l#c.ensh_mi "Incumbent X ENMI"
GDPgrowth "GDP Growth Rate" 
1.inc_cab_l#c.GDPgrowth "Incumbent X GDP Growth Rate"
1.inc_cab_l#c.moderate "Incumbent X Moderated Position"
moderate "Moderated Position"
1.nparty "Niche Party"
majelect "Majoritarian Election"
federal "Federalism"
directpres "Presidentialism"
pvote_l "% Vote{\sub t-1}"
_cons "Constant")
addnotes("Note: The Dependent variable is percentage vote for the party.");



/* Run the Models for Table A7	*/
/* Including controls for whether the PM party	*/
/* if a party was apart of any cabinet since the last election	*/
/* if the outgoing government was a coalition and the 	*/
/* Effective Number of Electoral Parties in the last election	*/

/*Table A7 - mixed effects with coalition controls	*/

xtmixed pvote
	c.ensh_mi##i.inc_cab_l pvote_l
	c.GDPgrowth##i.inc_cab_l
	c.moderate##i.inc_cab_l

	1.nparty L1.prime_minister L1.coalgov L1.cabinet_party L1.enep
 majelect federal directpres ,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_coalcontrols_full;	
	
	
 xtmixed pvote
	c.ensh_mi pvote_l
	c.GDPgrowth
	c.moderate

	1.nparty L1.prime_minister L1.coalgov L1.cabinet_party L1.enep
 majelect federal directpres if inc_cab_l==0,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_coalcontrols_opponly;	
	
	
	xtmixed pvote
	c.ensh_mi#i.inc_cab_l pvote_l
	c.GDPgrowth#i.inc_cab_l
	c.moderate#i.inc_cab_l
		1.nparty L1.prime_minister L1.coalgov L1.cabinet_party L1.enep
 majelect federal directpres if inc_cab_l==1,
|| edate_numeric: 
	|| country:,   robust;
		
		 estimates store ME_coalcontrols_inc;	
		 
	 #delimit;
 esttab  ME_coalcontrols_opponly ME_coalcontrols_inc ME_coalcontrols_full 
 using "figures\TableA7-ME Coal Controls.rtf", replace 
		b (%10.3f) se scalars("aic AIC" "bic BIC" "rmse Root Mean Squared Error" "ll Log-Likelihood" ) 
		obslast star(+ 0.10 * 0.05 ** 0.01 *** 0.001)
		label mtitles ( "Opposition" "Incumbents" "Full") nogaps
		title (\label{})
order(ensh_mi 
1.inc_cab_l#c.ensh_mi
moderate 
1.inc_cab_l#c.moderate
GDPgrowth
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l 
1.nparty
	 L.prime_minister 
	 L.coalgov 
	 L.cabinet_party 
	 L.enep
 majelect federal directpres
 pvote_l _cons ) 

keep(ensh_mi 1.inc_cab_l 
1.inc_cab_l#c.ensh_mi GDPgrowth 
1.inc_cab_l#c.GDPgrowth 
1.inc_cab_l#c.moderate
moderate 1.nparty
L.prime_minister 
	 L.coalgov 
	 L.cabinet_party 
	 L.enep
	 majelect 	
 federal directpres
pvote_l _cons )  

 coeflabels(
ensh_mi "ENMI" 
1.inc_cab_l "Incumbent"
1.inc_cab_l#c.ensh_mi "Incumbent X ENMI"
GDPgrowth "GDP Growth Rate" 
1.inc_cab_l#c.GDPgrowth "Incumbent X GDP Growth Rate"
1.inc_cab_l#c.moderate "Incumbent X Moderated Position"
moderate "Moderated Position"
1.nparty "Niche Party"
L.prime_minister "PM Party"
	 L.coalgov "Coalition Government"
	 L.cabinet_party "Cabinet Party"
	 L.enep "ENEP{\sub t-1}"
	 majelect "Majoritarian Election"
federal "Federalism"
directpres "Presidentialism"
pvote_l "% Vote{\sub t-1}"
_cons "Constant")
addnotes("Note: The Dependent variable is percentage vote for the party.");
